/*
@Time : 2020/7/30 13:36
@Author : lym
@File : OtherController
@Software: GoLand
*/
package controller

import (
	"encoding/json"
	"fmt"
	"gin-YiStudio-V1/common/consts"
	"gin-YiStudio-V1/common/response"
	"gin-YiStudio-V1/dao/model"
	"github.com/astaxie/beego/logs"
	"github.com/gin-gonic/gin"
)

/**
上传文件接口
*/

func UploadFile(context *gin.Context) {
	//读取文件
	header, e := context.FormFile("file")
	if e != nil {
		logs.Info("上传文件失败,e=", e)
	}
	//写文件
	e = context.SaveUploadedFile(header, "./"+header.Filename)
	context.JSON(200, gin.H{
		"msg": header,
	})
}

//测试bind
// @Summary 测试绑定json数据
// @Description 测试绑定json数据
// @Accept json
// @Produce json
// @Param postParam body model.PostParam true "postParam"
// @Success 200 {object} response.JsonResponse "{"code":200,"data":null,"msg":"测试bind success"}"
// @Failure 422 {object} response.JsonResponse "{"code":200,"data":null,"msg":"测试bind failed"}"
// @Router /v1/api/auth/bindTest [post]
func BindTest(ctx *gin.Context) {

	var p model.PostParam
	bind := ctx.ShouldBindJSON(&p)
	if bind != nil {
		fmt.Println(bind.Error())
		response.Bad(ctx, consts.ValiDatorError, nil, bind.Error())
	} else {
		marshal, _ := json.Marshal(p)
		logs.Info("BindTest:入参={%s}", string(marshal))
		response.Ok(ctx, consts.HttpOk, p, "success")
	}

}
